package com.example.demo.web;

import com.example.demo.common.ResponseResult;
import com.example.demo.common.ResponseResultFactory;
import com.example.demo.service.SMSMsgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

/**
 * @author lyc
 * @date 2019/6/10.
 */
@RestController
@Validated
public class SmsAction {

    @Autowired
    private SMSMsgService smsMsgService;

    /**
     * 发送验证码
     * @param tel
     * @param pwd
     * @return
     */
    @PostMapping("api/v1/sendMsg")
    public ResponseResult send(@NotNull(message = "手机号不能为空")
                       @Pattern(regexp = "^1\\d{10}$",message = "手机格式错误")
                        String tel,@NotNull(message = "密码不能为空") String pwd){
        String code = null;
        if(pwd.equals("dyZLqocz64r26E4dblQY69upQjaFTq")){
             code =  smsMsgService.send(tel);
        }

       return ResponseResultFactory.success("发送成功",code);
    }
}